package com.xea.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.xea.service.OnlineService;
import com.xea.service.ServiceFactory;
import com.xea.util.StringUtil;

public class OnlineGeneralAction extends DispatcherServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1932405126946046616L;
	
	
	/**
	 * 查询在线留言
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void search(HttpServletRequest request,HttpServletResponse response) throws Exception{
		OnlineService onlineDao = ServiceFactory.getOnlineService();
		String name=request.getParameter("name");
		if(StringUtil.isNullOrEmpty(name))
			name="";
		request.setAttribute("online", onlineDao.search(name));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("inner/general/online/list.jsp");
		dispatcher.forward(request, response);	
	}
	
	
	/**
	 * 查看在线留言
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void findById(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		OnlineService onlineDao = ServiceFactory.getOnlineService();
		String id=request.getParameter("id");
		request.setAttribute("online", onlineDao.findById(Integer.valueOf(id)));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher(request.getParameter("_url"));
		dispatcher.forward(request, response);
	}
	
	/**
	 * 查看在线留言详情
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void detail(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		OnlineService onlineDao = ServiceFactory.getOnlineService();
		String id=request.getParameter("id");
		request.setAttribute("online", onlineDao.findById(Integer.valueOf(id)));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("inner/general/online/detail.jsp");
		dispatcher.forward(request, response);
	}
	
	
}
